using System;

namespace SynoManager.DownloadStation
{
    public class DownloadStationConfiguration
    {
        private readonly DownloadStationService service;
        private DownloadStationClient.DownloadStationConfigData config;


        public DownloadStationConfiguration(DownloadStationService service)
        {
            this.service = service;
            config = service.client.GetConfiguration().data;
        }

        public void Save()
        {
            config = service.client.SaveConfiguration(config).data;
        }

        public int MaxActiveTasks
        {
            get { return config.dl_max_tasks; }
            set { config.dl_max_tasks = value; }
        }

        public ProcessOrder ProcessOrder
        {
            get { return (ProcessOrder) Enum.Parse(typeof(ProcessOrder), config.dl_ordering, true); }
            set { config.dl_ordering = value.ToString().ToLower(); }
        }

        public TimeSpan DownloadTimeFrom
        {
            get { return new TimeSpan(config.from_hr, config.from_min, 0); }
            set
            {
                config.from_hr = value.Hours;
                config.from_min = value.Minutes;
            }
        }

        public TimeSpan DownloadTimeTo
        {
            get { return new TimeSpan(config.to_hr, config.to_min, 0); }
            set
            {
                config.to_hr = value.Hours;
                config.to_min = value.Minutes;
            }
        }

        public DownloadStationClient.DownloadStationConfigVolumeInfo[] Volumes
        {
            get { return config.volume_list; }
        }

    }

    public enum ProcessOrder
    {
        Request,
        User,
    }
}